package com.xajh.duoduo.environment;

import com.xajh.duoduo.config.NumConfig;
import com.xajh.duoduo.eunm.position.AccountPosition;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

public class CurrentAccountPosition {
    private static volatile AtomicReference<AccountPosition> currentAccountPosition = new AtomicReference<>(null);
    private static volatile Integer groupIndex;
    private static volatile Integer itemIndex;
    private static volatile Map<Integer, List<AccountPosition>> accountsGroup = new HashMap<>();

    static {
        AccountPosition[] values = AccountPosition.values();
        int groupIndex = 0;
        List<AccountPosition> item = new ArrayList<>();
        for(int i = 0; i < values.length ; i ++){
            item.add(values[i]);
            if(((i + 1) % NumConfig.accountNum) == 0 ){
                accountsGroup.put(groupIndex,item);
                item = new ArrayList<>();
                groupIndex ++;
            } else if(i == values.length -1){
                accountsGroup.put(groupIndex,item);
            }

        }
    }

    public static AtomicReference<AccountPosition> getCurrentAccountPosition() {
        return currentAccountPosition;
    }

    public static void setCurrentAccountPosition(AtomicReference<AccountPosition> currentAccountPosition) {
        CurrentAccountPosition.currentAccountPosition = currentAccountPosition;
    }

    public static Integer getGroupIndex() {
        return groupIndex;
    }

    public static void setGroupIndex(Integer groupIndex) {
        CurrentAccountPosition.groupIndex = groupIndex;
    }

    public static Integer getItemIndex() {
        return itemIndex;
    }

    public static void setItemIndex(Integer itemIndex) {
        CurrentAccountPosition.itemIndex = itemIndex;
    }

    public static Map<Integer, List<AccountPosition>> getAccountsGroup() {
        return accountsGroup;
    }

    public static void setAccountsGroup(Map<Integer, List<AccountPosition>> accountsGroup) {
        CurrentAccountPosition.accountsGroup = accountsGroup;
    }
}
